const capitalService = require("../service/capital.service");
class CapitalController {
  async create(ctx, next) {
    ctx.request.body.id = ctx.user.id;
    const result = await capitalService.create(ctx.request.body);
    ctx.body = {
      code: 0,
      data: {
        status: 201,
        result
      }
    };
  }
  async resultAllCapital(ctx, next) {
    ctx.body = {
      code: 0,
      data: {
        status: 200,
        capital: ctx.resultCapital
      }
    };
  }
  async updateCapitalController(ctx, next) {
    ctx.request.body.id = ctx.resultCapital[0].id;
    console.log(ctx.request.body);
    const result = await capitalService.updateCapital(ctx.request.body);
    ctx.body = {
      code: 0,
      data: {
        status: 200,
        mes: "更新数据成功!",
        ...result
      }
    };
  }
  async deleteCapital(ctx, next) {
    const result = await capitalService.deleteCapital(ctx.resultCapital[0].id);
    ctx.body = {
      code: 0,
      data: {
        status: 200,
        mes: "删除数据成功!",
        ...result
      }
    };
  }
}

module.exports = new CapitalController();
